const Router = require("koa-router");

class BaseRoutes {
  constructor(prefix, controller) {
    this.router = new Router({ prefix });
    this.controller = controller;
  }

  registerRoutes(beforeFn) {
    if (beforeFn && typeof beforeFn === "function") {
      beforeFn(this.router);
    }

    this.router.get("/", this.controller.getPage);
    this.router.get("/page", this.controller.getPage);
    this.router.get("/list", this.controller.getList);

    this.router.post("/ids", this.controller.getByIds);
    this.router.post("/", this.controller.add);
    this.router.delete("/ids", this.controller.removes); // 批量删除
    this.router.delete("/soft/ids", this.controller.softDeletes); // 批量软删除
    this.router.delete("/soft", this.controller.softDelete); // 软删除

    this.router.get("/:id", this.controller.getById);
    this.router.put("/:id", this.controller.update);
    this.router.delete("/:id", this.controller.remove); // 删除

    return this.router;
  }
}

module.exports = BaseRoutes;
